from itsdangerous import JSONWebSignatureSerializer as ep
from dj31.settings.settings import SECRET_KEY
#加密

def dumps(dict,expires=600):
    """
    :param dict: 
    :param expires: 
    :return:  json str
    """
    signs = ep(SECRET_KEY,expires_in=expires) #加密，时间
    js_str = signs.dumps(dict).decode()
    return js_str

def loads(json_str,expires=600):
    '''

    :param json_str:
    :param expires:
    :return: str
    '''

    signs = ep(SECRET_KEY,expires_in=expires) #解密，时间
    try:
        json = signs.load(json_str)
    except:
        return None
    else:
        return json





